package com.jsgt.greekfire.ui.gfc.adapter

import android.content.Context
import android.text.TextUtils
import android.view.View
import android.widget.RelativeLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.android.material.shape.TriangleEdgeTreatment
import com.jsgt.greekfire.R
import com.jsgt.greekfire.bean.MyOrderBean
import com.jsgt.greekfire.common.util.TimeUtil

class CommissionAdapter(
    context: Context,
    layoutId: Int,
    data: ArrayList<MyOrderBean.ListBean>? = null
) : BaseQuickAdapter<MyOrderBean.ListBean, BaseViewHolder>(layoutId, data) {
    override fun convert(helper: BaseViewHolder, item: MyOrderBean.ListBean) {
        item?.let {
            if (!TextUtils.isEmpty(item?.createTime)) {
                var time = TimeUtil.dealDateFormat(item?.createTime)
                if (!TextUtils.isEmpty(time)) {
                    helper.setText(R.id.tvTime, time)
                }else{
                    helper.setText(R.id.tvTime, item?.createTime)
                }
            }
            var rllRemoval = helper.getView<RelativeLayout>(R.id.rllRemoval)
            var tvTurnoverNum = helper.getView<TextView>(R.id.tvTurnoverNum)
            var numturnoverNum = item.turnoverAmount - item.turnoverNum
            if(numturnoverNum != 0f){
                helper.setText(
                    R.id.tvTurnoverNum,
                    context.resources.getString(R.string.otc_text_order_turnover_num) + " " + numturnoverNum
                )
            }else{
                helper.setText(
                    R.id.tvTurnoverNum,
                    context.resources.getString(R.string.otc_text_order_turnover_num) + " " + item.dealNum
                )
            }
            helper.setText(R.id.tvCurrency, item?.coinCode)
                .setText(R.id.tvCurrency1, "/USDT")
                .setText(
                    R.id.tvPrice,
                    context.resources.getString(R.string.historical_order_text3) + " " + item.dealAmount
                )
                .setText(
                    R.id.tvNum,
                    context.resources.getString(R.string.coinList_text3) + " " + item.dealNum
                )
                .setText(R.id.tvTotal, item?.totalAmount.toString())
                .setText(R.id.tvTotal, item?.totalAmount.toString())
            if (item?.dealType == 1) {
                helper.setImageResource(R.id.ivType, R.mipmap.otc_order_sell)
                helper.setTextColor(
                    R.id.tvCurrency,
                    context.resources.getColor(R.color.otc_order_text_EF7149)
                )
            } else {
                helper.setImageResource(R.id.ivType, R.mipmap.otc_order_buy)
                helper.setTextColor(
                    R.id.tvCurrency,
                    context.resources.getColor(R.color.otc_order_text_07C087)
                )
            }
            if (item?.dealState == 1) {
                helper.setText(
                    R.id.tvStatus,
                    context.resources.getString(R.string.otc_text_order_ongoing)
                )
                helper.setTextColor(
                    R.id.tvStatus,
                    context.resources.getColor(R.color.otc_order_text_07C087)
                )
                rllRemoval.visibility = View.VISIBLE
                tvTurnoverNum.visibility = View.VISIBLE
            } else {
                helper.setText(
                    R.id.tvStatus,
                    context.resources.getString(R.string.otc_text_order_cancelled)
                )
                helper.setTextColor(
                    R.id.tvStatus,
                    context.resources.getColor(R.color.otc_order_text_EF7149)
                )
                rllRemoval.visibility = View.GONE
                tvTurnoverNum.visibility = View.GONE
            }

        }
    }

}